package com.naiterui.ehp.bs.emr.vo.patient;

import java.io.Serializable;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bs.emr.utils.LimitValueConfig;
import com.naiterui.ehp.bs.emr.utils.StringUtil;
import com.naiterui.ehp.bs.emr.exception.ExceptionCodes;

import io.swagger.annotations.ApiModelProperty;

/**
 * 可选择类档案：过敏药物、既往病史、遗传病、酒类
 *

 * @since 2.18
 */
public class MSelectOrOthersVO implements Serializable {

    private static final long serialVersionUID = -8109444174176201803L;
    /**
     * <状态：0无；1有>
     */
    @ApiModelProperty(value = "状态：0无；1有")
    private Short status;
    /**
     * <选中疾病，逗号分隔>
     */
    @ApiModelProperty(value = "选中疾病，逗号分隔")
    private String defaultSelect;
    /**
     * <其他（手动输入）>
     */
    @ApiModelProperty(value = "其他（手动输入）")
    private String others;

    private String defaultNames;

    public void validation() throws BusinessException {
        String others = this.getOthers();
        if (!LimitValueConfig.validateLimit(LimitValueConfig.LIMIT_DISEASE_OTHERS, others)) {
            throw new BusinessException(ExceptionCodes.INPUT_TOO_LONG);
        }

        // 表情符号校验
        if (!StringUtil.validateEmoji(others)) {
            throw new BusinessException(ExceptionCodes.EMOJI_ERROR);
        }
    }

    public String getDefaultNames() {
        if (StringUtils.isEmpty(this.defaultSelect) && StringUtils.isEmpty(this.others)) {
            return "";
        } else if (StringUtils.isEmpty(this.defaultSelect)) {
            this.defaultNames = this.others;
        } else if (StringUtils.isEmpty(this.others)) {
            this.defaultNames = this.defaultSelect;
        } else {
            this.defaultNames = this.defaultSelect + "," + this.others;
        }
        return this.defaultNames;
    }

    public void setDefaultNames(String defaultNames) {
        this.defaultNames = defaultNames;
    }

    public Short getStatus() {
        return this.status;
    }

    public void setStatus(Short status) {
        this.status = status;
    }

    public String getDefaultSelect() {
        return this.defaultSelect;
    }

    public void setDefaultSelect(String defaultSelect) {
        this.defaultSelect = defaultSelect;
    }

    public String getOthers() {
        if (StringUtils.isNotEmpty(this.defaultSelect) && StringUtils.isNotEmpty(this.others) && this.defaultSelect.contains(this.others)) {//
            // 选择默认项与输入其它冲突，过滤其它
            this.others = "";
        }
        return this.others;
    }

    public void setOthers(String others) {
        this.others = others;
    }

    @JsonIgnore
    public boolean isEmpty() {
        return this.status == null && StringUtils.isAllEmpty(this.defaultSelect, this.others);
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}
